package com.minsf.springbootinit.model.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.minsf.springbootinit.judge.codesandbox.model.JudgeInfo;
import com.minsf.springbootinit.model.entity.QuestionSubmit;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 题目提交
 *
 * @author a
 * @TableName question_submit
 */
@TableName(value = "question_submit")
@Data
public class QuestionSubmitVo implements Serializable {
    /**
     * id
     */
    private Long id;

    /**
     * 编程语言
     */
    private String language;

    /**
     * 用户代码
     */
    private String code;

    /**
     * 判题信息（json对象）
     */
    private JudgeInfo judgeInfo;

    /**
     * 题目 id
     */
    private Long questionId;

    /**
     * 判题状态 0-待判题、1-判题中、2-成功，3-失败
     */
    private Integer status;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    private UserVO user;

    private static final long serialVersionUID = 1L;

    public static QuestionSubmitVo objToVo(QuestionSubmit questionSubmit) {
        String judgeInfo = questionSubmit.getJudgeInfo();
        QuestionSubmitVo questionSubmitVo = new QuestionSubmitVo();
        BeanUtil.copyProperties(questionSubmit, questionSubmitVo, "judgeInfo");

        if (ObjectUtil.isNotEmpty(judgeInfo)) {
            questionSubmitVo.setJudgeInfo(JSONUtil.toBean(judgeInfo, JudgeInfo.class));
        }

        return questionSubmitVo;
    }
}